﻿using System;

namespace Property.Reloaders
{
    public partial class ConditionReloaderDecoratorPrototype<T>
    {
        private class DecoratorInstance : ReloaderDecorator<T>, IReloader
        {
            public DecoratorInstance(IReloaderPrototype<T> compositionBasePrototype,
                Func<T> getValue, Action<T> applyValue, Action<bool> applyStatus,
                Func<bool> condition)
                : base(compositionBasePrototype, getValue, applyValue, applyStatus)
            {
                if (condition == null) throw new ArgumentNullException("condition");

                _Condition = condition;
            }

            //=//

            private readonly Func<bool> _Condition;

            public override void Go()
            {
                if (_Condition()) _CompositionBase.Go();
            }
        }
    }
}
